<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<%
    String path = request.getContextPath();
    String basePath = request.getServerName() + ":" + request.getServerPort() + path + "/";
    String baseUrlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<c:set var="baseUrlPath2" value="<%=baseUrlPath%>"/>
<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>java在线网盘系統-后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css" media="all">
    <script src="${ctx}/static/layui/layui.js"></script>
</head>
<body style="padding:30px;height: 100%;">
<blockquote class="layui-elem-quote" style="text-align: center;">
    文件管理：在这里可以新建网盘文件夹，上传网盘中文件，切换网盘文件夹
</blockquote>
<script>
    var sysMsg = "${sysMsg}";
    if (sysMsg != "")
        alert(sysMsg);
</script>

<table class="layui-table">
    <tr class="layui-bg-green">
        <th></th>
        <th>文件名</th>
        <th>文件类型</th>
        <th>大小</th>
        <th>上传时间</th>
        <th>权限</th>
        <th>删除</th>
    </tr>
    <c:if test="${requestScope.fatherFolder.id != null }">
        <tr>
            <td>
                <a href="/cloud/main/file?dir=${requestScope.fatherFolder.id }"><img src="/cloud/images/folder.png"
                                                                                     alt="folder"/></a>
            </td>
            <td>上级文件夹</td>
            <td>文件夹</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </c:if>
    <c:forEach var="list" items="${requestScope.folderList }">
    <tr>
        <td><a href="/cloud/main/file?dir=${list.id}"><img src="/cloud/images/folder.png" alt="folder"/></a></td>
        <td>${list.name }</td>
        <td>文件夹</td>
        <td></td>
        <td></td>
        <td></td>
        <td>
            <a href="/cloud/main/deleteDir?folder=${list.id}&fatherFolder=${requestScope.fatherFolder.id}">
                <img src="/cloud/images/delete.png" alt="delete"/>
            </a>
        </td>
    <tr>
        </c:forEach>
        <c:forEach var="list" items="${requestScope.fileList }">
         <c:if test="${list.status != 2}">
    <tr>
        <td><a href="download?file=${list.id }&folder=${requestScope.folderId}">
            <img
                    src="/cloud/images/download.png" alt="download"/></a>
        </td>
        <td>${list.name}</td>
        <td>${list.fileType }</td>
        <td>${list.size } KB</td>
        <td>${list.uploadTime }</td>
        <c:if test="${list.status == 0}">
            <td>
                <a href="setAccess?file=${list.id }&folder=${requestScope.folderId}"><img
                        src="/cloud/images/private.png" alt="status"/></a>
            </td>
        </c:if>
        <c:if test="${list.status == 1}">
            <td>
                <a href="setAccess?file=${list.id }&folder=${requestScope.folderId}"><img src="/cloud/images/public.png"
                                                                                          alt="status"/></a>
            </td>
        </c:if>
            <%--        <td><a href="delete?file=${list.id }&folder=${requestScope.folderId}">--%>
            <%--            <img src="/cloud/images/delete.png"--%>
            <%--                 alt="status"/>--%>
            <%--        </a></td>--%>
        <td>
            <a href="setAccess?file=${list.id }&folder=${requestScope.folderId}&status=${2}">
                <img src="/cloud/images/delete.png"
                     alt="status"/>
            </a> </td>
    </tr>
            </c:if>

    </c:forEach>
</table>
<div id="fileForm">
    <div id="upload" style="border: 2px solid #eee; border-radius: 5px;margin-bottom: 30px;">
        <blockquote class="layui-elem-quote" style="text-align: center;">
            请选择文件上传
        </blockquote>
        <form class="form-control" action="${ctx}/main/upload" method="post" enctype="multipart/form-data"
              accept-charset="utf-8">
            <div class="layui-form-item">
                <label class="layui-form-label">选择文件</label>
                <div class="layui-input-inline">
                    <input type="file" name="dataList" multiple/><br/>
                    <input type="hidden" name="path" value="${requestScope.folderId}"/>
                </div>
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn" style="display: inline-block;">
                        <i class="layui-icon layui-icon-upload"></i>上传文件
                    </button>
                </div>
            </div>

        </form>
    </div>
    <div id="folder" style="border: 2px solid #eee; border-radius: 5px;">
        <blockquote class="layui-elem-quote" style="text-align: center;">
            请在下面创建文件夹
        </blockquote>
        <form class="form-control" action="${ctx}/main/folderAdd" method="POST" accept-charset="utf-8">
            <div class="layui-form-item">
                <label class="layui-form-label">新建文件夹</label>
                <div class="layui-input-inline">
                    <input type="text" name="folderName" class="layui-input" style="display: inline-block;"/><br/>
                    <input type="hidden" name="path" value="${requestScope.folderId}"/>
                </div>
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn" style="display: inline-block;">
                        <i class="layui-icon layui-icon-add-1"></i>新建
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<c:if test="${shareUrl!=null}">
    <script>
        //JavaScript代码区域
        layui.use('layer', function () {
            var layer = layui.layer;
            //边缘弹出
            layer.open({
                type: 1 ,
                title: "分享地址显示,复制地址可分享",
                skin: 'layui-layer-molv', //样式类名
                area: ['500px', '200px'] ,
                content: '<textarea class="layui-textarea" style="width:100%;" rows="2">${baseUrlPath2}/main/shareUrl?name=${shareUrl}</textarea>',
                btn: '关闭',
                btnAlign: 'c', //按钮居中
                shade: 0.5, //不显示遮罩
                yes: function () {
                    layer.closeAll();
                }
            });

        });
    </script>

</c:if>

</body>
</html>
